﻿using DepIC.Attributes;
using DepIC.Helpers;
using NUnit.Framework;

namespace DepIC.Tests.Helpers
{
    [TestFixture]
    public class InjectAttributeHelperTests
    {
        #region Test Types

        private class TestClass
        {
            [Inject]
            public TestClass(int i) { }

            public TestClass(bool b) { }

            [Inject]
            protected TestClass(string s) { }

            [Inject]
            public bool PublicProperty { get; set; }

            [Inject]
            public bool PublicPropertyWithoutSetter
            {
                get { return true; }
            }

            public bool PublicPropertyWithoutAttribute { get; set; }

            public bool ProtectedProperty { get; set; }

            public void PublicMethod() { }
        }

        #endregion


        #region Tests
        
        [Test]
        public void Test_GetConstructors_Should_Return_Public_Constructor_With_Inject_Attribute()
        {
            // Arrange
            var type = typeof (TestClass);

            // Act
            var constructors = InjectAttributeHelper.GetConstructors(type);

            // Assert
            Assert.AreEqual(1, constructors.Length);
            Assert.AreEqual(typeof (int), constructors[0].GetParameters()[0].ParameterType);
        }

        [Test]
        public void Test_GetProperties_Should_Return_Public_Property_With_Inject_Attribute_And_Setter()
        {
            // Arrange
            var type = typeof(TestClass);

            // Act
            var properties = InjectAttributeHelper.GetProperties(type);

            // Assert
            Assert.AreEqual(1, properties.Length);
            Assert.AreEqual("PublicProperty", properties[0].Name);
        }

        #endregion
    }
}
